/*
 * @Author: 宋杰
 * @Date: 2021-03-09 14:54:16
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-03-15 15:52:55
 * @Description: 一家十一口(猜一字)vuex
 */
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 存储token
    // token: storage.get('token') ? storage.get('token') : '',
    token: "",
    userName: "" // 可选
  },
  
  getters: {
    get_token(state){
      return state.token || storage.get("token") || null;
    }
  },
  
  mutations: {
    // 修改token，并将token存入localStorage
    set_token(state, token) {
      state.token = token;
      storage.set('token', token);
      console.log('store、localstorage保存token成功！');
    },
    del_token(state) {
      state.token = "";
      storage.remove("token");
    },
    // 可选
    setUserInfo(state, userName) {
      state.userName = userName;
    }
  },
  actions: {
  },
  modules: {
  }
})
